package acm.pta15;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.StringTokenizer;

public class 老板的作息表2 {
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        Reader sc = new Reader();
        int n = sc.nextInt();
        String[][] time = new String[n][2];
        for (int i = 0; i < n; i++) {
            time[i] = sc.nextLine().split(" - ");
        }
        Arrays.sort(time, Comparator.comparing(a -> a[0]));
        String curr = "00:00:00";
        for (String[] t : time) {
            if(!curr.equals(t[0])) {
                out.println(curr + " - " + t[0]);
            }
            curr = t[1];
        }
        if (!curr.equals("23:59:59")) {
            out.println(curr + " - " + "23:59:59");
        }
        out.flush();
        out.close();
    }

    static class Reader {
        private BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        private StringTokenizer tokenizer = new StringTokenizer("");

        private String innerNextLine() {
            try {
                return reader.readLine();
            } catch (IOException ex) {
                return null;
            }
        }

        public boolean hasNext() {
            while (!tokenizer.hasMoreTokens()) {    //内存中没有
                String nextLine = innerNextLine();
                if (nextLine == null) {     //且没有下一行
                    return false;
                }
                tokenizer = new StringTokenizer(nextLine);  //读入一行
            }
            return true;
        }

        public String nextLine() {
            tokenizer = new StringTokenizer("");    //清空内存中的字符
            return innerNextLine();
        }

        public void clear() {
            tokenizer = new StringTokenizer("");
        }

        public String next() {
            hasNext();
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }
//    public BigInteger nextBigInt() {
//        return new BigInteger(next());
//    }
    }

}
